import {
	myCache,
	template
} from "@/utils.js"

export function getQrKey() {
	let timeStamp = new Date().getTime();
	const url = `/login/qr/key?time=${timeStamp}`;
	return template(url);
}
export function loginCellPhoneApi(data) {
	let timeStamp = new Date().getTime();
	const url = `/login/cellphone?time=${timeStamp}&phone=${data.phone}&password=${data.password}`;
	return template(url);
}

export function getStatusApi(data) {
	let timeStamp = new Date().getTime();
	var url = `/login/qr/check?time=${timeStamp}`;
	var host = "http://localhost:3000";
	return new Promise(function(resolve, reject) {
		const success = function(res) {
			try {
				if (res.data.code) {
					resolve(res);
				} else {
					reject("error:" + (res.data.errMsg || "返回错误信息字段msg缺失"));
				}
				return;
			} catch (e) {
				reject("except:" + JSON.stringify(e));
			}
		};
		const fail = function(err) {
			reject("fail:" + JSON.stringify(err));
		};
		uni.request({
			sslVerify: false,
			url: host + url,
			data,
			success,
			fail
		});
	});
}
//轮播图
export function getBanner() {
	const url = `/banner?type=2`;
	return template(url);
}
//推荐歌单
export function getRcmd() {
	const url = `/personalized`;
	return template(url);
}
//歌单详情
export function getPlaylistDetail(data) {
	const url = `/playlist/detail?id=${data.id}`;
	return template(url);
}
//获取榜单
export function getToplist() {
	const url = `/toplist`;
	return template(url);
}
//获取音乐
export function getSongUrlApi(data) {
	const url = `/song/url/v1?id=${data.ids}&level=exhigh`;
	return template(url);
}
//获取音乐详情
export function getSongDetailApi(data) {
	const url = `/song/detail?ids=${data.ids}`;
	return template(url);
}
//获取评论
export function getCommentApi(data) {
	const url =
		`/comment/new?type=${data.type}&id=${data.id}&sortType=${data.sortType}&pageNo=${data.pageNo}&cursor=${data.cursor||''}&cookie=${myCache('cookie')}`;
	return template(url);
}
//发表评论
export function postCommentApi(data) {
	let url;
	if (data.t != 0) {
		url =
			`/comment?t=${data.t}&type=${data.type}&id=${data.id}&content=${data.content}&cookie=${data.cookie}`;
	} else {
		url =
			`/comment?t=${data.t}&type=${data.type}&id=${data.id}&commentId=${data.commentId}&cookie=${data.cookie}`;
	}
	return template(url);
}
//点赞评论
export function postLikeComment(data) {
	const url =
		`/comment/like?t=${data.t}&type=${data.type}&id=${data.id}&cid=${data.cid}&cookie=${data.cookie}`;
	return template(url);
}
//登录状态
export function getLoginStatus(data) {
	var host = "http://localhost:3000";
	const url = `/login/status`;
	return new Promise(function(resolve, reject) {
		const success = function(res) {
			try {
				if (res.data.data.code == 200) {
					resolve(res.data.data);
				} else {
					reject("error:" + (res.data.errMsg || "返回错误信息字段msg缺失"));
				}
				return;
			} catch (e) {
				reject("except:" + JSON.stringify(e));
			}
		};
		const fail = function(err) {
			reject("fail:" + JSON.stringify(err));
		};
		uni.request({
			method: "POST",
			sslVerify: false,
			url: host + url,
			data,
			success,
			fail
		});
	});
}
//获取用户
export function getProfile(data) {
	var host = "http://localhost:3000";
	const url = `/user/detail?uid=${data.uid}`;
	return new Promise(function(resolve, reject) {
		const success = function(res) {
			try {
				if (res.statusCode == 200) {
					resolve(res.data);
				} else {
					reject("error:" + (res.data.errMsg || "返回错误信息字段msg缺失"));
				}
				return;
			} catch (e) {
				reject("except:" + JSON.stringify(e));
			}
		};
		const fail = function(err) {
			reject("fail:" + JSON.stringify(err));
		};
		uni.request({
			sslVerify: false,
			url: host + url,
			success,
			fail,
		});
	});
}
//获取mv
export function getMvApi(data) {
	const url = `/mv/url?id=${data.id}&cookie=${myCache('cookie')}`;
	return template(url);
}
//获取 mv 数据
export function getMvDataApi(data) {
	const url = `/mv/detail?mvid=${data.mvid}&cookie=${myCache('cookie')}`;
	return template(url);
}
//获取推荐mv
export function getRcmdMvApi(data) {
	const url = `/personalized/mv`;
	return template(url);
}
//获取歌手详情
export function getArtistApi(data) {
	const url = `/artist/detail?id=${data.id}&cookie=${myCache('cookie')}`;
	return template(url);
}
//获取歌手粉丝
export function getArtistFansApi(data) {
	const url = `/artist/follow/count?id=${data.id}&cookie=${myCache('cookie')}`;
	return template(url);
}
//收藏/取消收藏歌手
export function getFollowApi(data) {
	const url = `/artist/sub?id=${data.id}&t=${data.t}&cookie=${myCache('cookie')}`;
	return template(url);
}
//获取每日推荐歌曲
export function getRcmdSongsApi(data) {
	const url = `/recommend/songs?cookie=${myCache('cookie')}`;
	return template(url);
}
//获取歌词
export function getLyricApi(data) {
	const url = `/lyric?id=${data.id}&cookie=${myCache('cookie')}`;
	return template(url);
}
//搜索建议
export function getSearchSuggestApi(data) {
	const url = `/search/suggest?keywords=${data.keywords}&type=mobile&cookie=${myCache('cookie')}`;
	return template(url);
}
//搜索详情
export function getSearchDetailApi(data) {
	const url =
		`/cloudsearch?keywords=${data.keywords}&type=${data.type}&offset=${data.offset||''}&cookie=${myCache('cookie')}`;
	return template(url);
}
//搜索默认
export function getSearchDefaultApi(data) {
	const url = `/search/hot/detail?cookie=${myCache('cookie')}`;
	return template(url);
}
//视频
export function getVideoApi(data) {
	const url = `/video/category/list`;
	return template(url);
}